#include<bits/stdc++.h>
using namespace std;
#define MAX 100005
#define QMAX 1000005
struct car{
    int l,r;
    bool operator < (const car &a) const{
        if(r<a.r)return 1;
        else if(r>a.r)return 0;
        else if(l<a.l)return 1;
        else return 0;
    }
};
int s[MAX],v[MAX],a[MAX],exd[MAX],p[MAX],pq[QMAX],nextp[QMAX],prep[QMAX];
int exid[MAX],exidcnt=0;
car cars[MAX];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    scanf("%d",&t);
    int n,m,l,vl;
    for(int tt=0;tt<t;tt++){
        exidcnt=0;
        scanf("%d %d %d %d",&n,&m,&l,&vl);
        for(int i=0;i<n;i++){
            scanf("%d %d %d",&s[i],&v[i],&a[i]);
            exd[i]=-1;
        }
        for(int i=0;i<m;i++){
            scanf("%d",p+i);
        }
        double d=0.0;
        int vdif=0;
        for(int i=0;i<n;i++){
            if(a[i]==0)continue;
            if(a[i]>0){
                if(v[i]>vl){
                    exd[i]=s[i];
                    continue;
                }
                vdif=vl*vl-v[i]*v[i];
                d=(double)(vdif)/2.0/a[i];
                //cout<<"carid:"<<i<<" exddouble:"<<d;
                exd[i]=(int)d;
                exd[i]++;
                exd[i]+=s[i];
                //cout<<" exdint:"<<exd[i]<<endl;
            }else{
                if(v[i]<vl)continue;
                vdif=vl*vl-v[i]*v[i];
                d=(double)(vdif)/2.0/a[i];
                d+=s[i];
                //cout<<"carid:"<<i<<" exddouble:"<<d;
                exd[i]=(int)d;
                if(vdif%(2*a[i])==0)exd[i]--;
                if(exd[i]>l)exd[i]=l;
                //cout<<" exdint:"<<exd[i]<<endl;
            }
        }
        for(int i=0;i<=l;i++)pq[i]=0;
        for(int i=0;i<m;i++){
            pq[p[i]]=1;
        }
        //cout<<"pq:";
        //cout<<pq[0]<<" ";
        for(int i=1;i<=l;i++){
            pq[i]+=pq[i-1];
            //cout<<pq[i]<<" ";
        }//cout<<endl;
        int nexp=0;
        for(int i=0;i<=l;i++){
            nextp[i]=p[nexp];
            if(i==p[nexp])nexp++;
        }
        int prepp=m-1;
        for(int i=l;i>=0;i--){
            prep[i]=p[prepp];
            if(i==p[prepp])prepp--;
        }
        /*for(int i=0;i<=l;i++){
            cout<<"prep:"<<prep[i]<<" nextp:"<<nextp[i]<<endl;
        }*/
        int pmax=p[m-1];
        for(int i=0;i<n;i++){
            if(a[i]>0&&pmax>=exd[i]){
                exid[exidcnt]=i;
                exidcnt++;
            }else if(a[i]==0&&v[i]>vl&&pmax>=s[i]){
                exid[exidcnt]=i;
                exidcnt++;
            }else if(a[i]<0&&exd[i]!=-1){
                if(pq[exd[i]]-pq[s[i]-1]>=1){
                    //cout<<"pdif:"<<pq[exd[i]]-pq[s[i]-1]<<endl;
                    exid[exidcnt]=i;
                    exidcnt++;
                }
            }
        }
        printf("%d ",exidcnt);
        /*for(int i=0;i<exidcnt;i++){
            cout<<"exid:"<<exid[i]<<endl;
        }*/
        for(int i=0;i<exidcnt;i++){
            int tmp=exid[i];
            if(a[tmp]==0){
                cars[i].l=nextp[s[tmp]];
                cars[i].r=prep[l];
            }else if(a[tmp]>0){
                cars[i].l=nextp[exd[tmp]];
                cars[i].r=prep[l];
            }else{
                cars[i].l=nextp[s[tmp]];
                cars[i].r=prep[exd[tmp]];
            }
        }
        sort(cars,cars+exidcnt);
        /*for(int i=0;i<exidcnt;i++){
            cout<<"l:"<<cars[i].l<<" r:"<<cars[i].r<<endl;
        }*/
        int ans=0,pre=-1;
        for(int i=0;i<exidcnt;i++){
            car now=cars[i];
            if(pre>=now.l&&pre<=now.r)continue;
            ans++;
            pre=now.r;
        }
        printf("%d\n",m-ans);
    }
    return 0;
}